package com.example.mideaoem.api.funcs;

import org.json.JSONObject;

public class AirConditionerFuncs {

	//自动，制冷，送风，除湿，制热
	
	
	public static final int COLD_AC = 0;//单冷机
	public static final int COLDHOT_AC = 1;//冷暖机
	public static final int HOT_AC = 2;//单热机
	public static final int COLD_AC_SUB = 3;//单冷，仅制冷，送风
	
	public AirConditionerFuncs(String json) {
		
		if(json.equals("")){

		}
		
		try{
			JSONObject jsonobj = new JSONObject(json);
			this.eco = jsonobj.getBoolean("eco");
			this.eightHot = jsonobj.getBoolean("eightHot");
			this.cool = jsonobj.getBoolean("cool");
			this.hot = jsonobj.getBoolean("hot");
			this.leftrightFan = jsonobj.getBoolean("leftrightFan");
			this.powerCal = jsonobj.getBoolean("powerCal");
			this.nestCheck = jsonobj.getBoolean("nestCheck");
			this.dry = jsonobj.getBoolean("dry");
			this.strongHot = jsonobj.getBoolean("strongHot");
			this.dianfure = jsonobj.getBoolean("dianfure");
			this.auto = jsonobj.getBoolean("auto");
			this.updownFan = jsonobj.getBoolean("updownFan");
			this.strongCool = jsonobj.getBoolean("strongCool");
			this.unitChangeable = jsonobj.getBoolean("unitChangeable");
			this.special_eco = jsonobj.getBoolean("special_eco");
			this.hotcold = jsonobj.getInt("hotcold");
			if(!cool && !dry){
				this.hotcold = HOT_AC;
			}else if(!hot && !eightHot){
				if(auto)
					this.hotcold = COLD_AC;
				else
					this.hotcold = COLD_AC_SUB;
			}else{
				this.hotcold = COLDHOT_AC;
			}
			
		}catch(Exception e){
			everythingEnable();
			e.printStackTrace();
		}
		try{
			JSONObject jsonobj = new JSONObject(json);
			this.selfcheck = jsonobj.getBoolean("selfcheck");
		}catch(Exception e){
			e.printStackTrace();
			this.selfcheck = true;//如果无记录，则为true
		}
	}
	
	
	/***
	 * 阉割版制冷
	 * @return
	 */
	public AirConditionerFuncs toSubCool(){
		auto = false;
		hot = false;
		eightHot = false;
		cool = true;
		dry = false;
		
		eco = true;
		leftrightFan = true;
		unitChangeable = true;
		turbo = true;
		strongCool = true;
		return this;
	}
	
	/**
	 * 设置成单冷机
	 */
	public AirConditionerFuncs toOnlyCool(){
//		everythingEnable();
		auto = true;
		hot = false;
		eightHot = false;
		cool = true;
		dry = true;
		
		eco = true;
		leftrightFan = true;
		unitChangeable = true;
		turbo = true;
		strongCool = true;
		return this;
	}
	
	/**
	 * 设置成单热机
	 * @return
	 */
	public AirConditionerFuncs toOnlyHot(){
//		everythingEnable();
		auto = true;
		cool = false;
		dry = false;
		hot = true;
		eightHot = true;
		
		eco = true;
		leftrightFan = true;
		unitChangeable = true;
		turbo = true;
		strongCool = true;
		return this;
	}
	
	/**
	 * 全功能
	 * @return
	 */
	public AirConditionerFuncs toAllEnable(){
//		everythingEnable();
		auto = true;
		hot = true;
		eightHot = true;
		cool = true;
		dry = true;
		
		eco = true;
		leftrightFan = true;
		unitChangeable = true;
		turbo = true;
		strongCool = true;
		return this;
	}
	
	
	public void everythingEnable() {
		hot = true;
		eightHot = true;
		power = true;
		mode = true;
		temperature = true;
		windSpeed = true;
		airCheck = true;
		unitChangeable = true;
		eco = true;
		indoor_temperature = true;
		turbo = true;
		outdoor_temperature = true;
		updownFan = true;
		leftrightFan = true;
		cool = true;
		dry = true;
		auto = true;
		wind = true;
		mutilTemp = true;
		strongHot = true;
		nestCheck = true;
		dianfure = true;
		strongCool = true;
	}
	
	
	public AirConditionerFuncs() {
		// TODO Auto-generated constructor stub
	}
	
	private void everythingDisable() {
		// TODO Auto-generated method stub
		hot = false;
		eightHot = false;
		power = false;
		mode = false;
		temperature = false;
		windSpeed = false;
		airCheck = false;
		unitChangeable = false;
		eco = false;
		indoor_temperature = false;
		turbo = false;
		outdoor_temperature = false;
		updownFan = false;
		leftrightFan = false;
		cool = false;
		dry = false;
		auto = false;
		wind = false;
		mutilTemp = false;
		strongHot = false;
		powerCal = false;
		nestCheck = false;
		dianfure = false;
	}

	/**开关机*/
	private boolean power = true;
	
	/**模式*/
	private boolean mode = true;
	
	/**温度*/
	private boolean temperature = true;
	
	/**风速*/
	private boolean windSpeed = true;
	
	/**空调体检*/
	private boolean airCheck = false;
	
	
	/**室内温度*/
	private boolean indoor_temperature = false;
	
	/**强劲*/
	private boolean turbo = false;
	

	/**室外温度*/
	private boolean outdoor_temperature= false;
	
	/**上下风*/
	public boolean updownFan = false;
	
	/**单位转换*/
	public boolean unitChangeable = false;
	
	/**ECO*/
	public boolean eco = false;
	
	/**只有在制冷，除湿，自动有效的ECO*/
	public boolean special_eco = false;
	
	/**左右风*/
	public boolean leftrightFan = true;
	
	/**八度制热*/
	public boolean eightHot = false;
	
	/**制冷*/
	public boolean cool = true;
	
	/**制热*/
	public boolean hot = true;
	
	/**干燥*/
	public boolean dry = true;
	
	/**自动*/
	public boolean auto = true;
	
	/**送风*/
	private boolean wind = true;
	
	/**双温控制*/
	public boolean mutilTemp = true;
	
	/**单冷机=0；冷暖机=1；单热机=2*/
	public int hotcold;
	public boolean powerCal = false;//电量
	public boolean nestCheck = true;//滤网清洗
	public boolean nestNeedChange = true;//滤网更换
	
	private boolean dishui = false;//防滴水
	public boolean dianfure = false;//电辅热
	public boolean strongHot = false;//制热强劲风
	public boolean strongCool = true;//制冷强劲风 默认true
	
	public boolean selfcheck = true;//体检
	
	public int getDeviceType(){
		return hotcold;
	}
	
	/**
	 * 设备只有基础功能
	 */
	public void setBaseFunc(){
		power = true;
		mode = true;
		temperature = true;
		windSpeed = true;
		airCheck = false;
		unitChangeable = true;
		eco = false;
		indoor_temperature = false;
		turbo = true;
		outdoor_temperature = false;
		updownFan = false;
		leftrightFan = false;
		eightHot = false;
		
		cool = true;
		hot = true;
		dry = true;
		auto = true;
		wind = true;
		mutilTemp = true;
		selfcheck = false;
		powerCal = false;
		strongCool = true;
	}

	@Override
	public String toString() {
		
		return "{\"eco\":"+eco+
				",\"eightHot\":"+eightHot+
				",\"cool\":"+cool+
				",\"auto\":"+auto+
				",\"hot\":"+hot+
				",\"dry\":"+dry+
				",\"leftrightFan\":"+leftrightFan+
				",\"powerCal\":"+powerCal+
				",\"nestCheck\":"+nestCheck+
				",\"strongHot\":"+strongHot+
				",\"dianfure\":"+dianfure+
				",\"selfcheck\":"+selfcheck+
				",\"updownFan\":"+updownFan+
				",\"strongCool\":"+strongCool+
				",\"unitChangeable\":"+unitChangeable+
				",\"special_eco\":"+special_eco+
				",\"hotcold\":"+hotcold+
				"}";
		
	}
	
	
}
